<?php
use Cartalyst\Sentry\Facades\Laravel\Sentry as Sentry;

function isDisplayable($module) {
    return is_array($module) && isset($module['display'])&& isset($module['display']['url']);
}

$user = Sentry::getUser();
$avatar = $user->avatar == null ? Config::get('probackend::config.sites.avatar-default') : $user->avatar;
$username = $user->first_name . ' ' . $user->last_name;
$email = $user->email;
$modules= config("probackend::config.modules",array());
?>
<div class="sidebar collapse">
    <div class="sidebar-content">
        <!-- User dropdown -->
        <div class="user-menu dropdown">
            <a href="#" class="dropdown-toggle" data-toggle="dropdown">
                <img src="{{$avatar}}">
                <div class="user-info">{{$username}}<span>{{$email}}</span></div>
            </a>
            <div id="userinfo" class="popup dropdown-menu dropdown-menu-right"></div>
        </div>
        <!-- /user dropdown -->
        <!-- Main navigation -->
        <ul class="navigation">
            @foreach ($modules as $moduleID => $module) 
            <?php 
            $vPermistions = array();
            foreach (array_keys($module['permistions']) as $pName) {
                $vPermistions[] = $moduleID.'.'.$pName;
            }
            ?>
            <?php if($moduleID!=="dashboard"&&$user->su==0&&!$user->hasAnyAccess($vPermistions)) continue;?>
            <?php if (!isDisplayable($module)) continue; ?>
            @if (isset($module['display']['url']))
            <li class="{{(Request::path()==rtrim($prefix."/".$module['display']['url'],"/"))?"active":""}}" ><a href="/{{$prefix}}/{{$module['display']['url']}}"><span>{{translate($module['title'])}}</span> <i class="{{$module['display']['icon']}}"></i></a></li>
            @elseif(isset($module['display']['sections']))
            <li>
                <a href="#" class="expand level-closed" id="second-level"><span>{{translate($module['title'])}}</span> <i class="{{$module['display']['icon']}}"></i></a>
                <ul style="display: none;">
                    @foreach($module['display']['sections'] as $title => $url)
                    <li><a href="/{{$prefix}}/{{$url}}">{{translate($title)}}</a></li>
                    @endforeach
                </ul>
            </li>
            @endif
            @endforeach
        </ul>
        <!-- /main navigation -->
    </div>
</div>
